package com.dongge.action;

import com.dongge.annotation.HasRole;
import com.dongge.entity.Role;
import com.dongge.service.RoleService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by zhudong on 2016/8/25.
 */
@Repository
public class RoleAction extends ActionSupport {

    private long id;
    private String name;

    @Autowired
    private RoleService roleService;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @HasRole("admin")
    public String list(){
        List<Role> roles = roleService.getRoles();
        ActionContext.getContext().put("roles",roles);
        return "list";
    }

    @HasRole("admin")
    public String add(){
        return "add";
    }

    @HasRole("admin")
    public String create(){
        return "list";
    }
}
